package com.example.flshtarvel.controller;

import com.example.flshtarvel.service.RouteCollectMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
public class RouteCollectMapController {
    @Autowired
    RouteCollectMapService routeCollectMapService;

    //路线收藏
    @GetMapping("/routeCollect/{routeId}")
    public Map<String,Object> routeCollect(@PathVariable("routeId")String routeId, HttpSession session){
        Map<String,Object> map = new HashMap<String,Object>();
        int result = routeCollectMapService.routeCollect(routeId,(String)session.getAttribute("userId"));
        if(result==1){
            map.put("msg",1);
        }else{
            map.put("msg",0);
        }
        return map;
    }
    //取消收藏
    @GetMapping("/deleteRouteCollect/{routeId}")
    public Map<String,Object> deleteRouteCollect(@PathVariable("routeId")String routeId, HttpSession session){
        Map<String,Object> map = new HashMap<String,Object>();
        int result = routeCollectMapService.deleteRouteCollect(routeId,(String)session.getAttribute("userId"));
        if(result >= 1){
            map.put("msg",1);
        }else{
            map.put("msg",0);
        }
        return map;
    }
    //查询收藏    根据路线id 用户id
    @GetMapping("/seleteRouteCollect{routeId}")
    public Map<String,Object> selectRouteCollectByRouteIdAndUserId(@PathVariable("routeId")String routeId,
                                                                   HttpSession session){
        Map<String,Object> map = new HashMap<String,Object>();
        int result = routeCollectMapService.selectRouteCollectByRouteIdAndUserId(routeId,(String)session.getAttribute("userId"));
        if(result==1){
            System.out.println("1");
        }else{
            System.out.println("0");
        }
        return map;
    }

    //查询收藏数   根据路线id
    @GetMapping("/seleteRoutecollectCount")
    public Map<String,Object> selectRouteCollectByRouteId(String routeId){
        Map<String,Object> map = new HashMap<String,Object>();
        int result = routeCollectMapService.selectRouteCollectByRouteId(routeId);
        map.put("msg",1);
        map.put("count",result);
        return map;
    }


}
